package edu.webarchitechture.bank.ejb3.services;

import edu.webarchitechture.bank.ejb3.exception.CustomerNotFoundException;
import edu.webarchitechture.bank.ejb3.exception.AccountNotFoundException;
import edu.webarchitechture.bank.ejb3.exception.IllegalAccountTypeException;
import edu.webarchitechture.bank.ejb3.domain.Account;

import javax.ejb.Stateless;
import javax.persistence.PersistenceContext;
import java.security.InvalidParameterException;
import java.util.List;

import org.hibernate.Session;

/**
 * Bean class to implement the account manager interface.
 *
 * @author Inoka Dissanayaka.
 */
@Stateless
public class AccountManagerBean implements AccountManager {
    @PersistenceContext
    Session session;

    public void addCustomerToAccount(Long customerId, Long accountId) throws InvalidParameterException, CustomerNotFoundException, AccountNotFoundException {
        getAccountManagerDAO().addCustomerToAccount(customerId, accountId);
    }

    public Long createAccount(Account account, Long customerId) throws IllegalAccountTypeException, CustomerNotFoundException, InvalidParameterException {
        return getAccountManagerDAO().createAccount(account, customerId);
    }

    public List<Account> getAccountsOfCustomer(Long customerId) throws InvalidParameterException, CustomerNotFoundException {
        return getAccountManagerDAO().getAccountsOfCustomer(customerId);
    }

    public List<Long> getCustomerIds(Long accountId) throws InvalidParameterException, AccountNotFoundException {
        return getAccountManagerDAO().getCustomerIds(accountId);
    }

    public Account getAccount(Long accountId) throws InvalidParameterException, AccountNotFoundException {
        return getAccountManagerDAO().getAccount(accountId);
    }

    public void removeAccount(Long accountId) throws InvalidParameterException, AccountNotFoundException {
        getAccountManagerDAO().removeAccount();
    }

    public void removeCustomerFromAccount(Long customerId, Long accountId) throws InvalidParameterException, CustomerNotFoundException, AccountNotFoundException {
        getAccountManagerDAO().removeCustomerFromAccount(customerId, accountId);
    }

    public AccountManagerDAO getAccountManagerDAO() {
        return new AccountManagerDAO(session);
    }

	public List<Account> getServiceAccounts()
			throws edu.webarchitechture.bank.ejb3.exception.InvalidParameterException,
			AccountNotFoundException {
		return  getAccountManagerDAO().getServiceAccounts();
		
	}

	public boolean validateAccount(Long accNo)
			throws edu.webarchitechture.bank.ejb3.exception.InvalidParameterException,
			AccountNotFoundException {
		return  getAccountManagerDAO().validateAccount(accNo);
	}
}
